package com.xwn.bean.base;

import com.xwn.bean.entity.User;

import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Date;

/**
 * 基础实体
 * @Author duandw
 * @Date 2019/12/31 16:36
 **/
@Entity
public class BaseEntityNoAuto {
    /**
     * 主键id
     */
    @Id
    private String id;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 创建者
     */
    private String createBy;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 更新者
     */
    private String updateBy;

    public BaseEntityNoAuto(){

    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public void preInsert(){
        this.setCreateBy("ADMIN");
        this.setCreateTime(new Date());
        this.setUpdateBy("ADMIN");
        this.setUpdateTime(new Date());
    }

    public void preUpdate(User user){
        this.setUpdateBy(user.getUsername());
        this.setUpdateTime(new Date());
    }
}
